<?php
require_once(dirname(__FILE__).'/../db/excelDBHandler.php');
//headers for careating an excel report
header("Content-Type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=spreadsheet.xls");

function cleanData(&$str)
  {
    $str = preg_replace("/\t/", "\\t", $str);
    $str = preg_replace("/\r?\n/", "\\n", $str);
    if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
  }
  

$result = excelDBHandler::studentsToEvent();
$header_array=array("Id","First name","Last name","Adress" ,"Phone","Email");//new array to hold the header names of the excel 
$str_result="";
	
	
	while($row = mysql_fetch_assoc($result))
	{
		array_walk($row, 'cleanData');	
		$str_result=$str_result."\r\n".implode("\t", array($row['id'],$row['first_name'],$row['last_name'],$row['adress'],$row['phone'],$row['email']));
			
	}
	
	
	
	echo implode("\t",$header_array).$str_result;
?>